package com.tengju.bff.interfaces.app.message;

import com.tengju.bff.interfaces.app.message.facade.MessageCentreFacade;
import com.tengju.bff.interfaces.app.message.vo.MyMessageContentListForm;
import com.tengju.bff.interfaces.app.message.vo.MyMessageContentListVO;
import com.tengju.bff.interfaces.app.message.vo.MyMessageVO;
import com.tengju.bff.interfaces.shared.ApiResponse;
import com.tengju.bff.interfaces.shared.servlet.ServletContextUtil;
import com.tengju.bff.interfaces.shared.servlet.UserServletContext;
import com.tengju.support.application.message.PushCidBindService;
import com.tengju.support.domain.model.user.UserIdCode;
import com.tengju.user.domain.model.user.UserId;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * @author kezunfa
 * @Date: 2021/6/7 14:56
 * @Description: 
 */
@Slf4j
@RestController
@Api(tags = "app消息中心接口")
@RequestMapping(value = "message/centre")
public class MessageCentreController {

    private final MessageCentreFacade messageCentreFacade;
    private final PushCidBindService pushCidBindService;

    @Autowired
    public MessageCentreController(MessageCentreFacade messageCentreFacade, PushCidBindService pushCidBindService) {
        this.messageCentreFacade = messageCentreFacade;
        this.pushCidBindService = pushCidBindService;
    }

    @ApiOperation(value = "所有消息未读数量", notes = "所有消息未读数量")
    @RequestMapping(value = "/getAllUnreadMessageCount", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<Long> getAllUnreadMessageCount() {
        UserServletContext servletContext = ServletContextUtil.getServletContext();
        UserId userId = servletContext.getUserId();

        return ApiResponse.newSuccess(messageCentreFacade.getAllUnreadMessageCount(userId));
    }

    @ApiOperation(value = "我的消息-首页", notes = "我的消息-首页")
    @RequestMapping(value = "/getMyMessageVOList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<MyMessageVO> getMyMessageVOList() {
        UserServletContext servletContext = ServletContextUtil.getServletContext();
        UserId userId = servletContext.getUserId();
        return ApiResponse.newSuccess(messageCentreFacade.getMyMessageVOList(userId));
    }

    @ApiOperation(value = "我的消息-列表页", notes = "我的消息-列表页")
    @RequestMapping(value = "myMessage/content/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<MyMessageContentListVO> myMessageContentList(@RequestBody MyMessageContentListForm myMessageContentListForm) {
        UserServletContext servletContext = ServletContextUtil.getServletContext();
        UserId userId = servletContext.getUserId();
        return ApiResponse.newSuccess(messageCentreFacade.myMessageContentList(userId,myMessageContentListForm));
    }

    @ApiOperation(value = "cid绑定", notes = "cid绑定")
    @RequestMapping(value = "/push/bind/cid", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<Boolean> bindCid(String cid) {
        UserServletContext servletContext = ServletContextUtil.getServletContext();
        UserId userId = servletContext.getUserId();
        return ApiResponse.newSuccess(pushCidBindService
                .bind(new com.tengju.support.domain.model.user.UserId(userId.getValue()),cid));
    }


}
